package com.ruoyi.project.lesson.poster.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.common.service.ICommonService;
import com.ruoyi.project.lesson.poster.domain.LessonPoster;
import com.ruoyi.project.lesson.poster.mapper.LessonPosterMapper;
import com.ruoyi.project.lesson.poster.service.ILessonPosterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程海报Service业务层处理
 *
 * @author shixiangwen
 * @date 2020-12-07
 */
@Service
@DataSource(DataSourceType.KKFORMULA)
public class LessonPosterServiceImpl implements ILessonPosterService {

    @Autowired
    private LessonPosterMapper lessonPosterMapper;

    @Autowired
    ICommonService commonService;

    /**
     * 查询课程海报
     *
     * @param id 课程海报ID
     * @return 课程海报
     */
    @Override
    public LessonPoster selectLessonPosterById(Long id) {
        return lessonPosterMapper.selectLessonPosterById(id);
    }

    /**
     * 查询课程海报列表
     *
     * @param lessonPoster 课程海报
     * @return 课程海报
     */
    @Override
    public List<LessonPoster> selectLessonPosterList(LessonPoster lessonPoster) {
        return lessonPosterMapper.selectLessonPosterList(lessonPoster);
    }

    /**
     * 新增课程海报
     *
     * @param lessonPoster 课程海报
     * @return 结果
     */
    @Override
    public int insertLessonPoster(LessonPoster lessonPoster) {
        lessonPoster.setCreatedTime(DateUtils.getNowDate());
        return lessonPosterMapper.insertLessonPoster(lessonPoster);
    }

    /**
     * 修改课程海报
     *
     * @param lessonPoster 课程海报
     * @return 结果
     */
    @Override
    public int updateLessonPoster(LessonPoster lessonPoster) {
        return lessonPosterMapper.updateLessonPoster(lessonPoster);
    }

    /**
     * 删除课程海报对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLessonPosterByIds(String ids) {
        return lessonPosterMapper.deleteLessonPosterByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程海报信息
     *
     * @param id 课程海报ID
     * @return 结果
     */
    @Override
    public int deleteLessonPosterById(Long id) {
        return lessonPosterMapper.deleteLessonPosterById(id);
    }

    @Override
    public int getMaxSort(Long id) {
        return commonService.selectTableColumnMaxValue("lesson_poster", "sort", " lesson_id = " + id) + 1;
    }
}
